package com.hxzy.shop.feign.auth;

import com.github.pagehelper.PageInfo;
import com.hxzy.shop.common.dto.auth.req.*;
import com.hxzy.shop.common.dto.auth.resp.*;
import com.hxzy.shop.dto.auth.req.LoadUserReq;
import com.hxzy.shop.dto.auth.resp.LoadUserResp;
import com.hxzy.shop.dto.auth.resp.Oauth2TokenDto;
import com.hxzy.shop.fallback.auth.AuthFallback;
import com.hxzy.shop.vo.Result;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.cloud.openfeign.SpringQueryMap;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;
import java.util.Map;

/**
 * 功能描述:远程调用 auth服务接口
 *
 * @author tonneyyy
 */
@FeignClient(value = "auth",fallback = AuthFallback.class)
public interface AuthFeign {

    /**
     * 登录授权
     * @param parameters
     * @param merchantId
     * @return
     */
    @PostMapping(value = "/oauth/token")
    Result<Oauth2TokenDto> postAccessToken(@RequestParam Map<String, String> parameters, @RequestHeader("merchantId") String merchantId);


    /**
     * 获取登录角色权限(包含拥有的权限)
     *
     * @param req
     * @return
     */
    @PostMapping(value = "/ums/loadUser")
    Result<LoadUserResp> loadUser(@RequestBody LoadUserReq req);

    /**
     * 获取商户RSA
     * @return
     */
    @GetMapping(value = "/rsa/publicKey")
    Map<String, Object> getKey();


//    /**
//     * 访问auth远程服务
//     * @param pageNum
//     * @param pageSize
//     * @param roleName
//     * @param state
//     * @return
//     */
//    @GetMapping(value = "/ums/role/roleList")
//    Result<PageInfo<RoleListResp>> roleList(@RequestParam(value = "pageNum") Integer pageNum,
//                                            @RequestParam(value = "pageSize")Integer pageSize,
//                                            @RequestParam(value = "roleName")   String roleName,
//                                            @RequestParam(value = "state")   Boolean state);

    @GetMapping(value = "/ums/role/roleList")
    Result<PageInfo<RoleListResp>> roleList(@SpringQueryMap RoleListReq req);
    /**
     * 访问auth远程服务
     * @param roleId
     * @return
     */
    @GetMapping(value = "/ums/role/roleDetail/{roleId}")
    Result<RoleDetailResp> roleDetail(@PathVariable(value = "roleId") Long roleId);

    /**
     * 编辑角色
     * @param req
     * @return
     */
    @PutMapping(value = "/ums/role/editRole")
    Result<Object> editRole(@RequestBody EditRoleReq req);

    /**
     * 新增角色
     * @param req
     * @return
     */
    @PostMapping(value = "/ums/role/addRole")
    Result<Object> addRole(@RequestBody AddRoleReq req);

    /**
     * 更改角色状态
     * @param req
     * @return
     */
    @PostMapping(value = "/ums/role/changeRoleState")
    Result<Object> changeRoleState(@RequestBody ChangeRoleStateReq req);

    /**
     * 角色权限树
     * @param roleId
     * @return
     */
    @GetMapping(value = "/ums/role/roleAuthorityTree/{roleId}")
    Result<List<RoleAuthorityTreeResp>> roleAuthorityTree(@PathVariable(value = "roleId") Long roleId);

    /**
     * 修改角色权限
     * @param req
     * @return
     */
    @PostMapping(value = "/ums/role/changeRoleAuthority")
    Result<Object> changeRoleAuthority(@RequestBody ChangeRoleAuthorityReq req);

    /**
     * 账户分页查询
     * @param req
     * @return
     */
    @GetMapping(value = "/ums/account/list")
    Result<PageInfo<AccountListResp>> accountList(@SpringQueryMap AccountListReq req);

    /**
     * 新增账户
     * @param req
     * @return
     */
    @PostMapping(value = "/ums/account")
    Result<Object> addAccount(@RequestBody AddAccountReq req);

    /**
     * 帐号详情
     * @param accountId
     * @return
     */
    @GetMapping(value = "/ums/account/{accountId}")
    Result<AccountDetailResp> accountDetail(@PathVariable(value = "accountId") Long accountId);

    /**
     * 修改账户
     * @param req
     * @return
     */
    @PutMapping(value = "/ums/account")
    Result<Object> editAccount(@RequestBody EditAccountReq req);


}
